<!-- 新增合作车队 -->
<template>
  <div class="new-team-dialog">
    <el-dialog
      width="900px"
      class=""
      top="6vh"
      title="新增合作车队"
      :visible="$store.state.dialog.newTeam"
      @close="close">
      <el-row>
        <el-col :span="24">
          <el-card shadow="hover">
            <el-form :model="order" :rules="rules" ref="order" label-width="100px" size="mini">
              <el-row>
                <el-col :span="8">
                  <h3>合作公司</h3>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="公司全称" prop="shipname">
                    <el-input v-model="order.companyName" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="公司简介">
                    <el-input v-model="order.abbreviation" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话" prop="contactNumber">
                    <el-input v-model="order.contactNumber"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="注册账号" prop="accountNumber">
                    <el-input v-model="order.accountNumber"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-button type="primary" @click="submit('order')">查询</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <el-table
              :data="tableData2"
              style="width: 100%"
              @selection-change="handleSelectionChange"
              height="100">
              <el-table-column type="selection" align="center" width="50"></el-table-column>
              <el-table-column
                prop="CompanyName"
                label="公司名称"
                width="110">
              </el-table-column>
              <el-table-column
                prop="CompanySite"
                label="公司类型">
              </el-table-column>
              <el-table-column
                prop="FullName"
                label="公司联系人">
              </el-table-column>
              <el-table-column
                prop="Mobile1"
                label="公司联系电话"
                width="130">
              </el-table-column>
              <el-table-column
                prop="Address"
                label="公司地址"
                width="130">
              </el-table-column>
              <el-table-column
                prop="NickName"
                label="注册账号"
                width="120">
              </el-table-column>
            </el-table>
          </el-card>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addCooperativeCleet" size="mini">添 加</el-button>
        <el-button type="info" @click="close" size="mini">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {insertUserInfo, GetUserInfo} from '../api/customerManagement'
export default {
  data () {
    // var checkPhone = (rule, value, callback) => {
    //   const reg = /^([1-9]\d{10})$/
    //   if (reg.test(value) || value === '') {
    //     callback()
    //   } else {
    //     return callback(new Error('请输入正确的手机号'))
    //   }
    // }
    return {
      order: {
        companyName: '',
        abbreviation: '',
        contactNumber: '',
        accountNumber: ''
      },
      tableData2: [],
      multipleSelection: [],
      rules: {
        accountNumber: [
          { required: true, message: '请输入注册账号', trigger: 'blur' }
        ]
        // contactNumber: [
        //   { validator: checkPhone, trigger: 'blur' }
        // ]
      }
    }
  },
  methods: {
    close () {
      this.$store.commit('hide_new_team_dialog')
    },
    // 查询
    async seachdiver () {
      const res = await GetUserInfo(this.order)
      if (res.status === 200) {
        this.tableData2 = res.data
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    },
    submit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.seachdiver()
        } else {
          return false
        }
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    // 新增合作车队
    async addCooperativeCleet () {
      if (this.multipleSelection.length !== 1) {
        this.$message({
          message: '请只选择一条消息',
          type: 'warning'
        })
        return false
      }
      const res = await insertUserInfo({
        customerId: this.multipleSelection[0].UserId, // 客户编号 ,
        customerName: this.multipleSelection[0].NickName.trim(), // 客户名称 ,
        fullName: this.multipleSelection[0].FullName, // 客户真实姓名 ,
        contactNumber: this.multipleSelection[0].Mobile1, // 联系电话 ,
        customerCompany: this.multipleSelection[0].CompanyName, // 客户公司 ,
        customerAddress: this.multipleSelection[0].Address // 客户公司地址
      })
      if (res.status === 200) {
        this.$notify({
          title: '提示',
          message: res.msg,
          type: 'success'
        })
        this.$parent.getTabeDate(1, 15)
        this.$store.commit('hide_new_team_dialog')
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
